/* -*- mode: C; c-basic-offset: 8 -*- 
 * week.c - print the week number of the year
 */

#include <sys/time.h>
#include <time.h>
#include <stdio.h>
#include <string.h>

#define MAX 80

int
main(int argc, const char *argv[])
{
	char buf[MAX];
	struct timeval clock;
	struct tm *now;
	int n_flag = 0;
	const char *progname = *argv++;
	if (*argv && !strcmp(*argv, "-v")) {
		printf("%s version 1.0\n", progname);
		return 0;
	}
	if (*argv && !strcmp(*argv, "-h")) {
		printf("Usage: %s [-h|-v|-n]\n", progname);
		printf("Print the week number of the year (0-52). Options are:\n");
		printf("  -h this help\n");
		printf("  -v print version\n");
		printf("  -n number from 1 to 53 (like in Nokia devices)\n");
		return 0;
	}
	if (*argv && !strcmp(*argv, "-n")) {
		n_flag = 1;
	}
	gettimeofday(&clock, NULL);
	now = gmtime(&clock.tv_sec);
	strftime(buf, MAX, n_flag ? "%V" : "%W", now);
	printf("%s\n", buf);
	return 0;
}
